package com.example.android.architecture.blueprints.todoapp.data.source;

import android.content.Context;
import android.support.annotation.NonNull;

import com.example.android.architecture.blueprints.todoapp.ApplicationModule;
import com.example.android.architecture.blueprints.todoapp.ToDoApplication;

import javax.inject.Singleton;

import dagger.Component;

/**
 * This is a Dagger component. Refer to {@link ToDoApplication} for the list of Dagger components
 * used in this application.
 * <P>
 * Even though Dagger allows annotating a {@link Component @Component} as a singleton, the code
 * itself must ensure only one instance of the class is created. This is done in {@link
 * ToDoApplication}.
 */
// TasksRepositoryModule 提供
@Singleton
@Component(modules = {TasksRepositoryModule.class, ApplicationModule.class})
public interface TasksRepositoryComponent {

    //提供给 TasksComponent 进行注入到 TasksPresenter(TasksRepository tasksRepository, TasksContract.View tasksView)
    //的参数中 TasksRepository 参数
    //而 TasksRepository 对象的构造函数是  TasksRepository(@Remote TasksDataSource tasksRemoteDataSource,
    // @Local TasksDataSource tasksLocalDataSource)
    //所以又需要 TasksRepositoryModule.class 提供的  abstract TasksDataSource provideTasksLocalDataSource(TasksLocalDataSource dataSource);
    //和  abstract TasksDataSource provideTasksRemoteDataSource(FakeTasksRemoteDataSource dataSource); 对象
    //而 TasksLocalDataSource   @Inject public TasksLocalDataSource(@NonNull Context context)和 FakeTasksRemoteDataSource 对象又需要
    // Context 对象 所以用提供了  ApplicationModule.class 对象提供 的    @ProvidesContext provideContext() {return mContext;}
    //这样就完成了整个的依赖注入
    // 这样对我暴漏了 TasksRepository 对象，可用于其他 Component 对象使用，进行依赖
    TasksRepository getTasksRepository();
}
